package demo4;

class  OutClass{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    //静态内部类
    static class InnerClass{
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;

        public void test(){
            OutClass outClass = new OutClass();
            System.out.println(outClass.data1);//不能直接调用外部类非静态成员变量/方法
            System.out.println(data3);
            System.out.println(data4);
            System.out.println("test方法被执行了...");
        }
    }
}

class  OutClass2{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    //内部类
    class InnerClass{
        public int data1 = 100;
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;

        public void test(){
            OutClass outClass = new OutClass();
            System.out.println(outClass.data1);
            System.out.println(OutClass2.this.data1);
            System.out.println(this.data1);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println("test方法被执行了...");
        }
    }
}

class Out{
    public void test1(){
        System.out.println("haha");
    }
}

interface IA{
    void test1();
}

public class Test {

    public static void main(String[] args) {
        new IA(){
            @Override
            public void test1() {
                System.out.println("haha");
            }
        }.test1();
        //这个类实现了IA接口并且同时重写了test1这个方法；
        IA ia = new IA(){
            @Override
            public void test1() {
                System.out.println("haha");
            }
        };
        ia.test1();
    }

    public static void main3(String[] args) {
        new Out(){

        }.test1();

        new Out(){
            @Override
            public void test1() {
                System.out.println("hehe");
            }
        }.test1();
    }

    public static void main2(String[] args) {
        //如何实例化一个实例内部类对象
        OutClass2 outClass2 = new OutClass2();
        OutClass2.InnerClass innerClass = outClass2.new InnerClass();
        innerClass.test();
    }

    public static void main1(String[] args) {
        //如何实例化一个静态内部类对象
        OutClass.InnerClass innerClass = new OutClass.InnerClass();
        innerClass.test();
    }
}
